//
//  ViewController.m
//  AILove
//
//  Created by 甘世清 on 2023/12/15.
//

#import "ViewController.h"
#import "HomeViewController.h"
#import "PeopleListViewController.h"
#import "MessageViewController.h"
#import "MeViewController.h"
#import "VipPopView.h"
@interface ViewController ()<YPTabBarDelegate>
@property (nonatomic , strong) HomeViewController * homeVC;
@property (nonatomic , strong) PeopleListViewController * listVC;
@property (nonatomic , strong) MessageViewController * messageVC;
@property (nonatomic , strong) MeViewController * meVC;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = UIColor.whiteColor;
    [self SQ_uiViewForSelf];
}
-(void)SQ_uiViewForSelf{
    self.tabBar.backgroundColor = SQHexColor(@"#000000", 0.6);
    self.tabContentView.delegate = self;
    [self setTabBarFrame:CGRectMake(0, SCREEN_HEIGHT-FootHeight-40, SCREEN_WIDETH, 40+FootHeight)
        contentViewFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    self.tabContentView.defaultSelectedTabIndex = 1;
    self.viewControllers = [NSMutableArray arrayWithObjects:self.homeVC, self.listVC,self.messageVC,self.meVC,nil];
    [self.tabBar setItemContentHorizontalCenterAndMarginTop:10 spacing:6];
    
    
    [self SQ_Header];
    
}

/**
 *  点击了index
 */
- (void)tabContentView:(YPTabContentView *)tabConentView didClickedTabAtIndex:(NSUInteger)index{
    if ([tabConentView.selectedController isKindOfClass:[HomeViewController class]] && index == 0) {
        [[NSNotificationCenter defaultCenter] postNotificationName:@"doubleClick" object:nil];
    }
}

- (void)viewWillAppear:(BOOL)animated{
//    NSArray * popArray = [LSTPopView getAllPopViewForParentView:self.view];
//    for (LSTPopView * pop  in popArray) {
//        if ([pop.identifier isEqualToString:@"viprootVC"]&&[UserModel share].isVip) {
//            [pop dismiss];
//        }
//    }
}

-(void)SQ_vipPopView{
    UserModel * model = [UserModel share];
    if (model.isVip) {
        return;
    }
    VipPopView * vc = [[VipPopView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDETH, SCREEN_HEIGHT)];
    LSTPopView * pop = [LSTPopView initWithCustomView:vc
                                           parentView:self.view
                                             popStyle:LSTPopStyleSmoothFromBottom dismissStyle:LSTDismissStyleSmoothToBottom];
    pop.hemStyle = LSTHemStyleCenter;
    pop.identifier = @"viprootVC";
    [pop pop];
    LSTPopViewWK(pop)
      [vc setVipBlock:^{
        [wk_pop dismiss];
    }];
}

- (void)SQ_Header{
    NSMutableDictionary * dic = [[NSMutableDictionary alloc]init];
    [HttpTool post:Url6 paramDic:dic successBlock:^(BaseModel * _Nonnull httpModel) {
        UserModel * mo = [UserModel share];
        UserModel* model = [UserModel mj_objectWithKeyValues:httpModel.data];
        model.token = mo.token;
        model.score = mo.score;
        [UserModel updateLocalUserModel:model];
    } andFailBloc:^(BaseModel * _Nonnull httpModel, NSError * _Nullable error) {
        
    }];
}



- (HomeViewController *)homeVC{
    if (!_homeVC) {
        _homeVC = [[HomeViewController alloc]init];
        _homeVC.yp_tabItemImage = SQGetImage(@"图标-未选中-4");
        _homeVC.yp_tabItemSelectedImage = SQGetImage(@"图标-选中-4");
    }
    return _homeVC;
}
- (PeopleListViewController *)listVC{
    if (!_listVC) {
        _listVC = [[PeopleListViewController alloc]init];
        _listVC.yp_tabItemImage = SQGetImage(@"图标-未选中");
        _listVC.yp_tabItemSelectedImage = SQGetImage(@"图标-选中");
    }
    return _listVC;
}
- (MessageViewController *)messageVC{
    if (!_messageVC) {
        _messageVC = [[MessageViewController alloc]init];
        _messageVC.yp_tabItemImage = SQGetImage(@"图标-未选中-2");
        _messageVC.yp_tabItemSelectedImage = SQGetImage(@"图标-选中-3");
    }
    return _messageVC;
}
- (MeViewController *)meVC{
    if (!_meVC) {
        _meVC = [[MeViewController alloc]init];
        _meVC.yp_tabItemImage = SQGetImage(@"图标-未选中-3");
        _meVC.yp_tabItemSelectedImage = SQGetImage(@"图标-选中-2");
    }
    return _meVC;
}


@end
